package com.example.systemend.service.GoodsImpl;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author 权哥
 * @version 1.0
 * @date 2022/6/6 12:00
 */
//用于产生订单编号
@Service
public class OrderNum {

    public String date(){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
        String date1= dateFormat.format(date).toString();
        String year=date1.substring(0,4);
        String month=date1.substring(5,7);
        String day=date1.substring(8,10);
        return year+month+day;
    }

    // 生成随机数
    public String makeNum(int k,int bound){
        Random random = new Random();
        //生成一个随机数[0,9999999) 末尾加上“”表明是字符串类型
        String num = random.nextInt(bound) + "";
        StringBuffer stringBuffer = new StringBuffer();
        //不足7位用0填充
        for (int i = 0; i < k - num.length(); i++) {
            stringBuffer.append("0");
        }
        num = stringBuffer.toString() + num;
        return num;
    }


    public static void main(String[] args) {
        OrderNum orderNum=new OrderNum();
        System.out.println(orderNum.date()+orderNum.makeNum(6,999999));

    }

}
